<?php use_stylesheets_for_form($form) ?>
<?php use_javascripts_for_form($form) ?>
<?php use_javascript('/js/jq/jq.ajaxupload.js'); ?>
<script type="text/javascript">
    $(document).ready(function() {
        uploadPhotoProduct("product/uploadImage");
        $("#product_price").keyup(
            function(){
                cur_val = $(this).val(); 
                val_secure = $("#costo_seguro").val();
                $("#product_price_secure_transport").val(cur_val * val_secure );
            }
        );
        $("#product_number_libras").keyup(
            function(){
                libras_product = $(this).val(); 
                val_libra = $("#costo_libra").val();
                $("#product_price_libras").val(libras_product * val_libra );
            }
        );
        $('#toggleCheck').change(function(){
            $('#toggleEntrega').toggle();
        });
    })
</script>
<table width="100%">
    <tr>
        <td width="50%">
            <form action="<?php echo url_for('product/'.($form->getObject()->isNew() ? 'create' : 'update').(!$form->getObject()->isNew() ? '?id_product='.$form->getObject()->getIdProduct() : '')) ?>" method="post" <?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?>>
                <?php if (!$form->getObject()->isNew()): ?>
                <input type="hidden" name="sf_method" value="put" />
                <?php endif; ?>
                <input type="hidden" name="costo_seguro" id="costo_seguro" value="0.3" />
                <input type="hidden" name="costo_libra" id="costo_libra" value="2.5" />
                <table>
                    <tfoot>
                    <tr>
                        <td colspan="2">
                        <?php echo $form->renderHiddenFields(false) ?>
                        &nbsp;<a href="<?php echo url_for('product/index') ?>">Back to list</a>
                        <?php if (!$form->getObject()->isNew()): ?>
                            &nbsp;<?php echo link_to('Delete', 'product/delete?id_product='.$form->getObject()->getIdProduct(), array('method' => 'delete', 'confirm' => 'Are you sure?')) ?>
                        <?php endif; ?>
                        <input type="submit" value="Save" />
                        </td>
                    </tr>
                    </tfoot>
                    <tbody>
                    <?php echo $form->renderGlobalErrors() ?>

                    <tr>
                        <th><?php echo $form['id_category']->renderLabel() ?></th>
                        <td>
                        <?php echo $form['id_category']->renderError() ?>
                        <?php echo $form['id_category'] ?>
                        </td>
                    </tr>
                    <tr>
                        <th><?php echo $form['id_subcategory']->renderLabel() ?></th>
                        <td>
                        <?php echo $form['id_subcategory']->renderError() ?>
                        <?php //echo $form['id_subcategory'] ?>
                            
                            <input type="checkbox" id="toggleCheck" name="togglebox" value="value1" checked="checked">
                            Yo tengo entrega a domicilio
                        </td>
                    </tr>
                            
                            
                        </td>
                    </tr>
                    <tr>
                        <th><?php echo $form['id_producer']->renderLabel() ?></th>
                        <td>
                        <?php echo $form['id_producer']->renderError() ?>
                        <?php echo $form['id_producer'] ?>
                        </td>
                    </tr>
                    <tr>
                        <th><?php echo $form['name_product']->renderLabel() ?></th>
                        <td>
                        <?php echo $form['name_product']->renderError() ?>
                        <?php echo $form['name_product'] ?>
                        </td>
                    </tr>
                    <tr>
                        <th><?php echo $form['upc_product']->renderLabel() ?></th>
                        <td>
                        <?php echo $form['upc_product']->renderError() ?>
                        <?php echo $form['upc_product'] ?>
                        </td>
                    </tr>
                    <tr>
                        <th><?php echo $form['price']->renderLabel() ?></th>
                        <td>
                        <?php echo $form['price']->renderError() ?>
                        <?php echo $form['price'] ?>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <input type="checkbox" id="toggleCheck" name="togglebox" value="value1" checked="checked">
                            Yo tengo entrega a domicilio
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2" id="toggleEntrega" style="padding-bottom: 30px;">
                            <table width="100%">
                                <tr>
                                    <th><?php echo $form['price_secure_transport']->renderLabel() ?></th>
                                    <td>
                                    <?php echo $form['price_secure_transport']->renderError() ?>
                                    <?php echo $form['price_secure_transport'] ?>
                                    </td>
                                </tr>
                                <tr>
                                    <th><?php echo $form['number_libras']->renderLabel() ?></th>
                                    <td>
                                    <?php echo $form['number_libras']->renderError() ?>
                                    <?php echo $form['number_libras'] ?> Lbs. <br />
                                        <?php echo $form['price_libras'] ?> $
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    
                    <tr>
                        <th><?php echo $form['quantity']->renderLabel() ?></th>
                        <td>
                        <?php echo $form['quantity']->renderError() ?>
                        <?php echo $form['quantity'] ?>
                        </td>
                    </tr>
                    <tr valign="top">
                            <td width="6%" class="" style="padding-top: 15px;" >
                                <div id="imageFIELD" style="min-height: 110px; min-width: 170px;">
                                <?php $uploadProduct = sfConfig::get('sf_upload_dir').'/products/'.$form->getObject()->getIdUser().'/small_'.$form->getObject()->getImage(); ?>
                                <?php if(file_exists($uploadProduct)): ?>
                                    <?php echo image_tag('/uploads/products/'.$form->getObject()->getIdUser().'/small_'.$form->getObject()->getImage(), 'class="borderImage"')?>
                                <?php else:?>
                                    <?php echo image_tag('no_image_available.jpg', 'border=0 width="150" height="110" class="borderImage"');?>
                                <?php endif;?>
                                </div>
                            <?php if(file_exists($uploadProduct)): ?>
                                <div id="deleteImage" style="margin-left: 40px;" >
                                        <?php echo jq_link_to_remote(__('Eliminar imagen'), array(
                                        'update'  =>  'imageFIELD',
                                        'url'     =>  'product/deleteImage?id='.$form->getObject()->getIdProduct(),
                                        'script'  => true,
                                        'confirm' => __('Esta seguro que desea eliminar la imagen?'),
                                        'before'  => "$('#imageFIELD').html('<div>". image_tag('preload.gif','title="" alt=""')."</div>');",
                                        'complete'=> "$('#deleteImage').html('');"
                                        ));
                                        ?>
                                </div>
                            <?php endif;?>

                            </td>
                            <td style="padding-top: 15px; vertical-align: top" >
                                <?php echo $form['image']->renderLabel() ?><br/>
                                <?php echo $form['image'] ?>
                                <?php echo $form['image']->renderError() ?>
                                <span class="msn_help"><?php echo $form['image']->renderHelp() ?></span>
                            </td>
                    </tr>
                    <tr>
                        <td colspan="2">&nbsp;</td>
                    </tr>
                    <tr>
                        <th style="vertical-align: top"><?php echo $form['description']->renderLabel() ?></th>
                        <td>
                        <?php echo $form['description']->renderError() ?>
                        <?php echo $form['description'] ?>
                        </td>
                    </tr>
                    <tr>
                        <th><?php echo $form['devasin']->renderLabel() ?></th>
                        <td>
                        <?php echo $form['devasin']->renderError() ?>
                        <?php echo $form['devasin'] ?>
                        </td>
                    </tr>


                    </tbody>
                </table>
                </form>
                <div align="left" style="border: 0px solid #000; margin-top: 50px;">
                <?php if (!$form->getObject()->isNew()): ?>
                    <?php echo jq_form_remote_tag(array(
                        'url'    => 'product/saveBulletPoint?id='.$sf_request->getParameter('id_product'),
                        'update' => 'indicator',
                        'position' => 'after',
                        'loading'  => "$('#indicator').show()",
                        'complete' => "$('#indicator').hide()",
                        'success'  => "listBulletsPointsProduct(".$sf_request->getParameter('id_product').");",
                    ), array(
                        'id'     => 'bullets',)
                    ) ?>

                <table width="100%">
                    <tr>
                        <td>
                            &nbsp;<h2><?php echo __('Agregue las especificaciones del producto') ?> </h2>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <label>Bullet</label><br />
                            <input type="text" id="name_bullet_point" name="name_bullet" value="" />
                            <input type="submit" value="<?php echo __('Agregar') ?>" class="secondary-button" />
                        </td>
                    </tr>
                </table>

                <div id ="indicator" align="left" style="display: none" >
                    <p><?php echo image_tag('preload.gif'); ?></p>
                </div>
                <div id="bulletsPoint" align="left">
                    <table>
                    <tbody>
                        <?php foreach ($bullet_point_products as $bullet_point_product): ?>
                        <tr>
                            <td><a href="<?php echo url_for('bullet/edit?id_bullet_point='.$bullet_point_product->getIdBulletPoint()) ?>"><?php echo $bullet_point_product->getIdBulletPoint() ?></a></td>
                            <td>&nbsp;&nbsp;<?php echo $bullet_point_product->getBulletPointDescripcion() ?></td>
                        </tr>
                        <?php endforeach; ?>
                    </tbody>
                    </table>
                </div>

                </form>
                <?php endif;?>
            </div>
            
        </td>
        <!-- ALBUM -->
        <td valign="top">
            <?php if (!$form->getObject()->isNew()): ?>
                <div id="galeria" class="frameForm" align="left">
                    <div class="frameHomeImages">
                        <table cellpadding="0" cellspacing="0" border="0"  id="resultsList">
                        <thead>
                            <tr>
                            <th><h2><?php echo __('Uploaded images')?></h2>
                            </th>
                            </tr>
                        </thead>
                        <tr>
                            <td style="padding-left: 8px">
                            <span class="msn_help">
                            <?php $appYml = sfConfig::get('app_upload_images_album');
                                    echo __('La imagen debe ser jpeg, jpg, png or gif<br />');
                                    echo __('La imagen debe tener un peso máximo de '.(sfConfig::get('app_image_size_text')).'<br /> ');
                                    echo __('La imagen debe tener un tamaño mínimo de '.$appYml['size_1']['image_width_1'].' x '.$appYml['size_1']['image_height_1'].' pixeles');
                            ?>
                            </span>



                            <br/><br/>
                            <div id="upload_image">Click aquí para cargar imagen</div>
                            <br/>
                            <div id="msg_upload">
                                <!-- <span class="msn_help"><?php //echo __('Only jpg, gif and png files allowed');?></span> -->
                            </div>
                            <div id="wait"></div>
                            <div id="fileUpload"> </div>
                            <div id="mimeError" class="msn_error" style="display:none" > La extensión no está permitida</div>
                            </td>
                        </tr>
                        <tr>
                            <td id="image_poster" style="padding-left:11px;">
                            <?php if (!$form->getObject()->isNew()): ?>
                                <?php $idSeller = sfContext::getInstance()->getUser()->getAttribute('id_user_seller'); ?>
                                <?php $appYml = sfConfig::get('app_upload_images_product'); ?>
                                <?php foreach($album_products as $item): ?>
                                        <?php $idContent = $item->getIdContent(); ?>
                                        
                                        <div id="item_<?php echo $idContent;?>" class='contentPicture'>
                                            <div id="deleteHomeImage">
                                            <?php echo jq_link_to_remote('Eliminar imagen', array(
                                                'update'   =>  'item_'.$idContent,
                                                'url'      =>  'product/deleteImageGallery?id='.$idContent,
                                                'script'   => true,
                                                'confirm'  => __('Are you sure you want to delete the selected data?'),
                                                'before'   => "$('#item_".$idContent."').html('<div align=center><br />".image_tag('preload.gif','title="" alt=""')."</div>');",
                                                'complete' => "$('#item_".$idContent."').remove();"
                                            ),'class="delete"');
                                            ?>
                                            </div>
                                            <div id="elemento_<?php echo $idContent;?>" class="imagePoster">
                                                <?php if(is_file(sfConfig::get('sf_upload_dir').'/products/'.$idSeller.'/gallery/'.$appYml['size_3']['pref_3'].'_'.$item->getImage())):?>
                                                <?php echo image_tag('/uploads/products/'.$idSeller.'/gallery/'.$appYml['size_3']['pref_3'].'_'.$item->getImage(),' alt="" title="" class="  ')  ?>
                                                <?php else:?>
                                                <?php echo image_tag('no_image_available.jpg')  ?>
                                                <?php endif;?>
                                            </div>                                        
                                        </div>

                                <?php endforeach; ?>
                            <?php endif; ?>
                            <div id="preLoad" class="contentPicture"  style="display:none">
                                <br/><br/>
                                <img alt="" src="/images/preload.gif"> <br/><br/><p align="center">Cargando imagen</p>
                            </div>
                            </td>
                        </tr>
                        
                        </table>
                    </div>
                    <br/>
                    
                </div>
            <?php endif?>
        </td>
    </tr>
</table>

